package com.yjd.comm.borrow.convert;

import java.util.List;

import com.yjd.comm.borrow.enums.BorrowReturnOverdueAdvanceEnum;
import com.yjd.comm.borrow.enums.OverduePartEnum;
import com.yjd.comm.borrow.enums.ReturnStatusEnum;
import com.yjd.comm.borrow.model.ArrearsFormModel;
import com.yjd.comm.borrow.util.BorrowUtil;
import com.yjd.comm.util.DateUtil;

/**
 * <b>description</b>：标的回款报表数据转换器 <br>
 * <b>time</b>：2014-11-17下午3:43:47 <br>
 * <b>author</b>： ready likun_557@163.com
 */
public class ArrearsFormModelConvert {

	public static ArrearsFormModel convert(ArrearsFormModel model)
			throws Exception {
		if (model != null) {
			// 应该还款日期
			model.getStrMap().put(
					"reday",
					DateUtil.timestampToDateString(model.getReday(),
							DateUtil.PATTERN_yyyy_MM_dd));
			// 是否垫付
			model.getStrMap().put("advance",
					BorrowReturnOverdueAdvanceEnum.getDesc(model.getAdvance()));
			// 垫付时间
			model.getStrMap().put(
					"advancetime",
					DateUtil.timestampToDateString(model.getAdvancetime(),
							DateUtil.PATTERN_yyyy_MM_dd_HH_mm_ss));
			model.getStrMap().put("uptime",
					DateUtil.timestampToDateString(model.getUptime()));
			// 状态
			model.getStrMap().put("status",
					ReturnStatusEnum.getDesc(model.getStatus()));
			// 实际回款日期(相对于投资人来说)
			model.getStrMap()
					.put("actualRetime1",
							DateUtil.timestampToDateString(BorrowUtil
									.getActualReturnTime(model,
											OverduePartEnum.invest)));
			// 实际回款日期(相对于借款人和平台来说)
			model.getStrMap()
					.put("actualRetime2",
							DateUtil.timestampToDateString(BorrowUtil
									.getActualReturnTime(model,
											OverduePartEnum.borrow)));
		}
		return model;
	}

	public static List<ArrearsFormModel> convert(List<ArrearsFormModel> models)
			throws Exception {
		if (models == null || models.size() == 0) {
			return models;
		}
		for (ArrearsFormModel model : models) {
			convert(model);
		}
		return models;
	}
}
